package com.chd.ledger_server.service.impl;

import com.chd.ledger_server.entity.PipeStandard;
import com.chd.ledger_server.dao.PipeStandardDao;
import com.chd.ledger_server.service.PipeStandardService;
import com.chd.ledger_server.domain.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管材标准表(PipeStandard)表服务实现类
 *
 * @author makejava
 * @since 2025-07-07 09:25:31
 */
@Service("pipeStandardService")
public class PipeStandardServiceImpl implements PipeStandardService {
    @Resource
    private PipeStandardDao pipeStandardDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pipeStaId 主键
     * @return 实例对象
     */
    @Override
    public PipeStandard queryById(Integer pipeStaId) {
        return this.pipeStandardDao.queryById(pipeStaId);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo queryAllPipeStandardsByPage(PageDto pageDto) {
        //空值处理
        if (pageDto.getPage() == null || pageDto.getSize() == null) {
            pageDto.setPage(1);
            pageDto.setSize(10);
        }
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<PipeStandard> list = pipeStandardDao.queryAll(pageDto.getPipeStandard());
        PageInfo<PipeStandard> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param pipeStandard 实例对象
     * @return 实例对象
     */
    @Override
    public PipeStandard insert(PipeStandard pipeStandard) {
        this.pipeStandardDao.insert(pipeStandard);
        return pipeStandard;
    }

    /**
     * 修改数据
     *
     * @param pipeStandard 实例对象
     * @return 实例对象
     */
    @Override
    public PipeStandard update(PipeStandard pipeStandard) {
        this.pipeStandardDao.update(pipeStandard);
        return this.queryById(pipeStandard.getPipeStaId());
    }

    /**
     * 通过主键删除数据
     *
     * @param pipeStaId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pipeStaId) {
        return this.pipeStandardDao.deleteById(pipeStaId) > 0;
    }
}
